﻿using System;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Web.UI.WebControls;

namespace _513X0018_web08
{
    public partial class AspDatagrid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string str = "Provider = Microsoft.Jet.OLEDB.4.0; " + "Data Source = " + ConfigurationManager.AppSettings["GrocerPath"]; //grocer.mdb is declared in Web Config
            OleDbConnection conn = new OleDbConnection(str);
            str = "Select * " + "from Products";
            OleDbDataAdapter adapter = new OleDbDataAdapter(str, conn);
            DataSet datSet = new DataSet();
            adapter.Fill(datSet, "Products");
            DataGrid1.DataSource = datSet;
            DataGrid1.DataBind();
        }
        protected void DataGrid1_Edit(object sender, DataGridCommandEventArgs e)
        {
            DataGrid1.EditItemIndex = e.Item.ItemIndex;
            DataGrid1.DataBind();
        }
        protected void DataGrid1_Update(object sender, DataGridCommandEventArgs e)
        {
            DataGrid1.EditItemIndex = -1;
            DataGrid1.DataBind();
        }
        protected void DataGrid1_Cancel(object sender, DataGridCommandEventArgs e)
        {
            DataGrid1.EditItemIndex = -1;
            DataGrid1.DataBind();
        } 
    }
}